Skip to content

Conversation

@mikeash
Copy link
Contributor

@mikeash mikeash commented Nov 5, 2025

Instead of copying the data and the type and witnesses separately, use the size in the value witness table and copy everything at once.

copyTypeInto assumed the type was an ordinary existential. When it was actually an extended existential, it would do an incorrect cast and read part of a pointer as the number of witness tables to copy. This would typically result in a large buffer overflow and crash. At this point we already know the type's size, so we can use that info directly rather than essentially recomputing it.

rdar://163980446

@mikeash mikeash requested a review from al45tair as a code owner November 5, 2025 22:41
Instead of copying the data and the type and witnesses separately, use the size in the value witness table and copy everything at once.

copyTypeInto assumed the type was an ordinary existential. When it was actually an extended existential, it would do an incorrect cast and read part of a pointer as the number of witness tables to copy. This would typically result in a large buffer overflow and crash. At this point we already know the type's size, so we can use that info directly rather than essentially recomputing it.

rdar://163980446
@mikeash mikeash force-pushed the fix-extended-existential-copying branch from 43c4feb to 7bb9579 Compare November 8, 2025 04:38
@mikeash
Copy link
Contributor Author

mikeash commented Nov 8, 2025

@swift-ci please test

@mikeash mikeash merged commit 662f8d4 into swiftlang:main Nov 10, 2025
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants